﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows;

namespace DiasEngineDate
{
    class Conning
    {
        //全局变量
        public SqlConnection sqlconn;
        private string sqlstring = "Data Source=" + Login.serveraddr + ";Database=" + Login.dataname + ";Uid=" + Login.sqlname + ";Pwd=" + Login.sqlpwd;
        public Conning()
        {
            if (Login.serveraddr == "" || Login.dataname == "" || Login.sqlname == "")
            {
                MessageBox.Show("连接失败？", "数据库连接参数不正确？请检查配置文件参数？");
                return;
            }
            //链接数据库。
            sqlconn = new SqlConnection(sqlstring);
            //打开链接字符串
            try
            {
                sqlconn.Open();
            }
            catch (Exception)
            {
                //显示连接数据库打开失败
            }


            if (sqlconn.State == ConnectionState.Open)
            {

            }
            else
            {
                MessageBox.Show("连接失败？", "请检测数据库配置是否正确？");
                return;
            }
        }
    }
}
